import java.io.*;

/**
 * An EMail object represents a single email address
 * @author Joshua Zeiser
 *
 */
public class EMail implements Comparable<EMail>, Serializable{

	private String eMailAddress;

	/**
	 * constructor that provides the eMailAddress at instantiation
	 * @param eMail
	 */
	public EMail(String eMail) {
		this.eMailAddress = eMail;
	}
	
	/**
	 * constructor without eMailAddress, sets to empty String
	 */
	public EMail() {
		this.eMailAddress = "";
	}
	
	/**
	 * @return String the eMailAddress
	 */
	public String geteMailAddress() {
		return eMailAddress;
	}

	/**
	 * @param eMailAddress the eMailAddress to set
	 */
	public void seteMailAddress(String eMailAddress) {
		this.eMailAddress = eMailAddress;
	}
	
	/**
	 * implements toString() method to return EMail as a String
	 * @return String the eMailAddress
	 */
	@Override
	public String toString()
	{
		return eMailAddress;
	}
	
	/**
	 * Implements/overrides compareTo
	 * Allows comparison of EMail objects
	 * ***Not used for task 3 but implemented for early testing***
	 * @param e EMail object
	 * @return int comparison result
	 */
	@Override public int compareTo(EMail e) {
		final int BEFORE = -1;
		final int EQUAL = 0;
		final int AFTER = 1;
		
		if(this.equals(e)) return EQUAL;
		
		int comparison = this.eMailAddress.compareTo(e.geteMailAddress());
		if(comparison != 0) return comparison;
		
		return EQUAL;
	}
	
	/**
	 * Implements and overrides default Object equals functionality
	 * Allows equality test of EMail objects
	 * ***Not used for task 3 but implemented for early testing***
	 * @param e Object
	 * @return boolean equality result
	 */
	@Override public boolean equals(Object e) {
		if(this == e) return true;
		if(!(e instanceof EMail)) return false;
		
		EMail e2 = (EMail)e;
		
		return (this.eMailAddress.equals(e2.geteMailAddress()));
	}

}
